package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    @Select("select count(*) from dish where category_id = #{id}")
    Integer countByCategoryId(Long id);

    // 分页查询
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 插入菜品
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    // 根据主键查询菜品
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    // 删除菜品
    void deleteByIds(List<Long> ids);

    @AutoFill(value =  OperationType.UPDATE)
    void update(Dish dish);

    List<Dish> list(Dish dish);

    @Select("select d.* from dish d left join setmeal_dish sb on d.id = sb.dish_id where sb.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);
}
